package org.example.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.entity.SpecKey;
import org.example.mapper.SpecKeyMapper;
import org.example.model.PageBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SpecKeyService {
    @Resource
    private SpecKeyMapper specKeyMapper;

    public PageBean<SpecKey> specKeyList(Integer page,Integer size){

        Page<SpecKey> specKeys = PageHelper.startPage(page, size);

        specKeyMapper.selectList(null);

      return   PageBean.<SpecKey>builder().data(specKeys.getResult())
              .total(specKeys.getTotal())
              .current(specKeys.getPageNum())
              .build();

    }

    public void addSpec(SpecKey specKey){
        specKeyMapper.insert(specKey);
    }

    public void editSpec(SpecKey specKey){
        specKeyMapper.updateById(specKey);
    }

    public SpecKey getSpecKey(Integer id){
       return specKeyMapper.selectById(id);
    }

    public void deleteSpecKey(Integer id){
        specKeyMapper.deleteById(id);
    }

    public List<SpecKey> getAll(){
        return specKeyMapper.selectList(null);
    }
}
